package sunmi.payment.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.NonNull;
import android.view.Gravity;

import mi.payment.R;

public class ForceNFCWarningDialog extends Dialog {

    public ForceNFCWarningDialog(@NonNull Context context) {
        this(context, R.style.UI_DefaultDialogStyle);
    }

    private ForceNFCWarningDialog(@NonNull Context context, int theme) {
        super(context, theme);
        init();
    }

    private Looper looper = Looper.getMainLooper();

    private Handler mHandler = new Handler(looper) {

        @Override
        public void handleMessage(Message msg) {
            boolean destroyed = getOwnerActivity().isDestroyed();
            if (destroyed) return;
            dismiss();
        }

    };

    private void init() {
        setContentView(R.layout.dialog_force_nfc_warning);
        if (getWindow() != null) {
            getWindow().getAttributes().gravity = Gravity.CENTER;
        }
        // 点击空白不取消
        setCanceledOnTouchOutside(false);
        // 点击返回按钮不取消
        setCancelable(false);
    }

    public void dismissDelayed(long delayMillis) {
        if (mHandler != null) {
            mHandler.sendEmptyMessageDelayed(0, delayMillis);
        }
    }


}
